package com.qf.dao;

import com.qf.bean.Student2;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.web.PageableDefault;

import java.util.List;

/**
 * IntelliJ IDEA -> springdata
 * 2019/12/2 15:38
 *
 * @author zmyao
 * 别看，我是渣渣。
 */
public interface Student2Dao  extends JpaRepository<Student2,Integer> {

    //学生姓名查询
    List<Student2> findBySnameContaining(String sname);
    //已知条件：年级编号，查询该年级的学生信息
    List<Student2> findByGrade2_Gid(int gid);

    //自己写hql语句
    @Query("from Student2  where stuid = ?1 ")
    Student2 findbyid(int sid);

    //查询通过id和年龄
    @Query("from Student2  where stuid = ?1 and sname like  ?2 ")
    Student2 findbyid_name(int sid , String sname);
@Query("from Student2  where stuid = :sid and sname like :suname ")
    Student2 findbyid_name1(@Param("sid") int sid , @Param("suname") String sname );
@Query("from Student2  where  grade2.gid =?1 ")
List<Student2> getStudent2sBygid(int gid);

//使用本地sql 查询学生列表
    @Query(value = " select  * from student2  where stuid = :sid  and sname like :studentname ",nativeQuery = true)
    List<Student2> getStudent2sBygid1(@Param("sid") int sid,@Param("studentname") String sname);
}
